<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>病案集中归档查询</title>
</head>
<body>
<div class="easyui-panel" data-options="fit:true,border:0">
	<div id="archivingQueryBar">
	   <span class="paddingTBL">
		    <div class="paddingB">
		    	<select id="arcQuery_rqlx" class="easyui-combobox" data-options="width:85,height:24">
		        	<option value="1" selected="selected">出院日期</option>
		        	<option value="2">归档日期</option>
		        </select>&nbsp;
				<input type="text" class="easyui-datebox" id="arcQuery_date1" data-options="width:115,height:24"/>
				<label>&nbsp;至&nbsp;</label>
				<input type="text" class="easyui-datebox" id="arcQuery_date2" data-options="width:115,height:24"/>
		        <label class="paddingL">出院科室&nbsp;</label>
				<input type="text" class="" id="arcQuery_fcydept" data-options="width:120,height:24"/>
			   	<label class="paddingL">出院病区&nbsp;</label>
			    <input type="text" class="" id="arcQuery_fcybq" data-options="width:120,height:24"/>&nbsp;
		    </div>
			<div class="paddingB"> 
		        <label class="labelWid5">病案号</label>
				<input id="arcQuery_fprn" class="easyui-textbox" data-options="prompt:'条码号/住院号',width:262,height:24" />
			    <label class="labelWid4 paddingL">姓&nbsp;名&nbsp;</label>
				<input type="text" class="easyui-textbox" id="arcQuery_fname" data-options="width:120,height:24"/>
		    	<label class="paddingL">主治医生&nbsp;</label>
				<input type="text" class="" id="arcQuery_fzydoc" data-options="width:120,height:24"/>
			</div> 
			<span> 
			    <span style="width:375px;border:0px solid red"> 
					<label style="color:blue">归档期限设置</label>&nbsp;&nbsp;
					<label>及时归档≤</label>
					<input type="text" onkeyup="onkeydownJsDay()" class="easyui-numberbox" id="arcQuery_jsDay" value="" data-options="width:30,height:24"/>
					<label>天</label>&nbsp;&nbsp;
					<label>逾期归档&gt;</label>
					<input type="text" onkeyup="onkeydownYqDay()" class="easyui-numberbox" id="arcQuery_yqDay" value="" data-options="width:30,height:24"/>
					<label>天</label>&nbsp;&nbsp;
				</span> 
			 
				<span style="width:205px;border:0px solid red"> 
					<label>按时归档介于</label><label id="arcQuery_jsDay_label"></label><label>&nbsp;至&nbsp;</label><label id="arcQuery_yqDay_label"></label><label>天</label>
				</span> 
				 
				<span style="width:185px;border:0px solid red"> 
					<label>已出院天数≥</label>
					<input type="text" class="easyui-numberbox" id="arcQuery_ycy" data-options="width:60,height:24"/>
					<label>天</label>
				</span>
			 </span> 
	    </span>
	    <span class="paddingLB" style="width:275px;border:0px solid red">  
		    <label class="labelWid4">归档状态</label>
			<select class="easyui-combobox" id="arcQuery_fstatus" data-options="width:120,height:24">
				<option value="0" selected="selected">全部</option>
	            <option value="1">已归档</option>
	            <option value="2">未归档</option>
		     </select>
		     <label class="paddingL"></label>
			 <a href="#" class="easyui-linkbutton" onclick="queryAllArchiving()">查 询</a>
	    </span> 
	</div>
 
	<table id="arcQueryGrid"></table>

</div>
<script type="text/javascript">

$(function(){
	//获取出院科室
	$("#arcQuery_fcydept").combobox({
		url:ctx + "/MedicalShootManage/getDept",
		valueField:"ftykh",
		textField:"fksname",
		width:120, 
		height:24,
		onLoadSuccess : function() {
			$('#arcQuery_fcydept').combobox('select', 'TZYQY');
		},
		onSelect : function(record){
			var code = record.ftykh;
			getCybs(code)
		}
	});
	
	//获取主治医生
	$("#arcQuery_fzydoc").combobox({
		url:ctx + "/MedicalShootManage/getZzDoc",
		valueField:"fzzdoctbh",
		textField:"fzzdoct",
		width:120, 
		height:24
	});
	
	$("#arcQuery_jsDay").numberbox({
		onChange:function(){
			var jsDay=$("#arcQuery_jsDay").numberbox("getValue");
			var yqDay=$("#arcQuery_yqDay").numberbox("getValue");
			if(jsDay<yqDay||jsDay=="" || yqDay==""||jsDay=="0" || yqDay=="0"){
				$("#arcQuery_jsDay_label").html(jsDay);
			}else{
				$.messager.alert('提示','及时归档天不能大于逾期归档天！','info');
			}
		}
	});
	
	$("#arcQuery_yqDay").numberbox({
		onChange:function(){
			var jsDay=$("#arcQuery_jsDay").numberbox("getValue");
			var yqDay=$("#arcQuery_yqDay").numberbox("getValue");
			if(jsDay<yqDay||yqDay=="" || jsDay==""||jsDay=="0" || yqDay=="0"){
				$("#arcQuery_yqDay_label").html(yqDay);
			}else{
				$.messager.alert('提示','逾期归档天不能小于及时归档天！','info');
			}
		}
	});
});

//获取出院病区
function getCybs(code){
	var ksbh = "";
	if(code != "" && code != null){
		ksbh = code;
	}
	$("#arcQuery_fcybq").combobox({
		url:ctx + "/Archiving/getAllFcybs",
		valueField:"fhiskh",
		textField:"fhisksname",
		width:120, 
		height:24,
		queryParams : {
			'ksbh' : ksbh
		}
		
	});
}

//查询数据
function queryAllArchiving(){
	var rqlx = $("#arcQuery_rqlx").combobox("getValue");
	var date1 = $("#arcQuery_date1").datebox("getValue");
	var date2 = $("#arcQuery_date2").datebox("getValue");
	var fcydept = $("#arcQuery_fcydept").combobox("getValue");
	var fcybq = $("#arcQuery_fcybq").combobox("getValue");
	var status = $("#arcQuery_fstatus").combobox("getValue");
	var fprn = $("#arcQuery_fprn").searchbox("getValue");
	var fname = $("#arcQuery_fname").textbox("getValue");
	var fzzDoc = $("#arcQuery_fzydoc").combobox("getValue");
	var jsDay = $("#arcQuery_jsDay").numberbox("getValue");
	var yqDay = $("#arcQuery_yqDay").numberbox("getValue");
	var ycyDay = $("#arcQuery_ycy").numberbox("getValue");
	if(jsDay>yqDay &&(jsDay!=""&&yqDay!=""&& jsDay!="0"&&yqDay!="0")){
		$.messager.alert('提示','逾期归档天不能小于及时归档天！','info');
		return ;
	}
	$("#arcQueryGrid").datagrid({
		url:ctx + "/Archiving/queryAllArchiving",
		queryParams:{
			"rqlx" : rqlx,
			"date1" : date1,
			"date2" : date2,
			"fcydept" : fcydept,
			"fzzDoc" : fzzDoc,
			"fprn" : fprn,
			"fname" : fname,
			"fcybq" : fcybq,
			"status" : status,
			"jsDay" :jsDay,
			"yqDay" :yqDay,
			"ycyDay" : ycyDay
		}
	});
}

//加载数据表格
$("#arcQueryGrid").datagrid({
	url:'',
	toolbar:"#archivingQueryBar",
	rownumbers:true,
	fitColumns:false,
	border : false,
	striped : true,
	fit : true,
	singleSelect: true,
	pagination : true,
	pageSize : 20,
	pageList : [ 20, 30,50 ],
	columns:[[
		{field:'fstatus',title:'状态',width:60,align:'center',
        	formatter : function(value,row,index){
        		if(value == null || value == "" ||  value == "0" ){
        			return "未归档";
        		}else{
        			return "已归档";
        		}
        		
        	}	
		},  
		{field:'days',title:'归档天数',width:80,align:'center'},  
		{field:'page',title:'归档页数',width:80,align:'center'},  
		{field:'fcydept',title:'出院科室',width:100,align:'center' },  
		{field:'fcybs',title:'出院病区',width:100,align:'center' },  
		{field:'fprn',title:'病案号',width:120,align:'center'},  
		{field:'fzyid',title:'住院ID',width:100,align:'center'},  
		{field:'ftimes',title:'次数',width:50,align:'center' },  
		{field:'fname',title:'姓名',width:80,align:'center' },  
		{field:'fsex',title:'性别',width:50,align:'center' },  
		{field:'fbarcode',title:'条码号',width:160,align:'center' },  
		{field:'fcydate',title:'出院日期',width:100,align:'center',
			formatter:function(value){
				return new Date(value).format("yyyy-MM-dd");
			}
		},  
		{field:'fzzdoct',title:'主治医生',width:100,align:'center' },  
		{field:'fzzdoctbh',title:'主治医生编号',width:100,align:'center',hidden:true },  
		{field:'fdate',title:'归档日期',width:100,align:'center',hidden:true },  
		{field:'detail',title:'详情',width:100,align:'center',hidden:true },	//存放没份病历的归档情况  
		{field:'frydate',title:'入院日期',width:100,align:'center',hidden:true,
			formatter:function(value){
				return new Date(value).format("yyyy-MM-dd");
			}	
		} 
	       ]],
	       onLoadSuccess:function(data){
	   		//获取当前页所有住院ID，通过住院ID查询没分病案的归档数量
	   		var array = data.rows;
	   		var fzyids = "";
	   		for (var i = 0; i < array.length; i++) {
	   			if(i > 0){
	   				fzyids += "," + array[i].fzyid;
	   			}else{
	   				fzyids += array[i].fzyid;
	   			}
	   		}
	   		 $.ajax({
	   			url : ctx + '/Archiving/getArchivingByFzyid' ,
	   			dataType : 'json',
	   			type : 'post',
	   			data : {
	   				'fzyids' : fzyids 
	   			},
	   			success : function(datas){
	   				//将每份病案归档的记录放入隐藏的表格中
	   				var rows = $('#arcQueryGrid').datagrid("getRows");
	   				var fzyid = "";
	   				var total = 0;
	   				var detail = "";
	   				for (var i = 0; i < datas.length; i++) {
	   					var arr = datas[i];
	   					for (var j = 0; j < arr.length; j++) {
	   						 fzyid = arr[0].fzyid;
	   						 total = arr[arr.length-1].total;
	   						 if(j <= 3){
	   							 if(j > 0){
	   								 detail += ","+""+arr[j].fname+"("+arr[j].number+")";
	   							 }else{
	   								 detail += ""+arr[j].fname+"("+arr[j].number+")";
	   							 }
	   						 }
	   					}
	   					for (var k = 0; k < rows.length; k++) {
	   						if(rows[k].fzyid == fzyid){
	   							$('#arcQueryGrid').datagrid('updateRow',{
	   								index: k,
	   								row:{
	   									page : "<div id='Details"+k+"' onclick='previewDetails("+k+")'><a href='#' style='cursor:help;'>"+total+"</a></div>",
	   									detail : detail
	   								}
	   							});
	   						}
	   					}
	   					fzyid = "";
	   					total = 0;
	   					detail = "";
	   				}
	   				
	   			},
	   			error : function(){
	   				$.messager.alert('提示','获取归档总数失败，请联系管理员！','info');
	   			}
	   	
	   		}); 
	   	}
});


//浏览归档详情
function previewDetails(index){
	var rows = $('#arcQueryGrid').datagrid("getRows")[index];
	var detail = rows.detail;
	var arr = [];
	arr = detail.split(",");
	var items = "";
	for (var i = 0; i < arr.length; i++) {
		items += "<li>"+(i+1)+"、"+arr[i]+"</li>"		
	}
	$('#Details'+index).tooltip({
			position : 'right',
			content : "<div style='width:250px;height:auto;'> <h4>归档明细  <span style='font-size:14px;'> (病案号:"+rows.fprn+")</span></h4><div style='margin: 2px 0px;'><ul class='description' style='list-style-type:none;'>"+items+"</ul> </div> </div>",
			onShow : function() {
				$(this).tooltip('tip').css({
					borderColor : '#666'
				});
				
			}
		}); 
}
</script>  
</body>
</html>